function commafy(num) {
  num = num + '';
  var reg = /(-?\d+)(\d{3})/;

  if(reg.test(num)){
    num = num.replace(reg, '$1,$2');
  }

  return num;
}

commafy(1234);

Doyle
844 声望16 粉丝

前端, angular, vue